package com.zhihesj.anan.monitor.controller;

import com.zhihesj.anan.message.Message;
import com.zhihesj.anan.message.MessageCodeEnum;
import com.zhihesj.anan.utils.SigarUtils;
import org.hyperic.sigar.SigarException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

@RestController()
@RequestMapping("/monitor/server")
public class serverController {

    @GetMapping("/getServerConfig")
    public Message getServerConfig(){
        System.out.println("开始获取系统信息");
        SigarUtils sigarUtils=new SigarUtils();
        SigarUtils.initSigar();
        Map<String, Object> map = new HashMap<>(16);
        try {
            map.put("cpu", SigarUtils.cpu());
            map.put("mem", SigarUtils.memory());
            map.put("property", SigarUtils.property());
            map.put("file", SigarUtils.file());
            System.out.println(map);
        } catch (SigarException e) {
            e.printStackTrace();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (Exception e){
            e.printStackTrace();
        }
        return Message.success(map);
    }
}
